/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycity.servlets;

import com.mycity.dao.PostTab;
import com.mycity.dao.UserTab;
import com.mycity.jsonops.PostOps;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author celikeins
 */
public class Profile extends Base{
    
    	public Profile(HttpServletRequest request, HttpServletResponse response) {
		super(request, response);
	}
	
	public void index() throws IOException, ServletException{
		UserTab user = getCurrentUser();
		if(user == null){
			response.sendRedirect("/MyCityWeb/login.jsp");
			return;
		}
		details(user.getUserId());
	}
        
        public void details(Long userId) throws IOException, ServletException{

		response.setContentType("text/html");
		UserTab user = getCurrentUser();
		if(user == null){
                        response.sendRedirect("/MyCityWeb/login.jsp");
			return;
		}
                PostTab[] posts = PostOps.getPostsByUserId(userId);
		request.setAttribute("user", user);
                request.setAttribute("postArray",posts );
		request.getRequestDispatcher("/profilePage.jsp").include(request, response);
	}
}
